<template>
  <div class="app-container">
    <div>
      <BasicBusiness ref="basicBusinessRef" />
    </div>
    <div style="padding: 50px">
      <Step ref="stepRef" />
    </div>
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="mini"
      label-width="170px"
    >
      <!-- <el-form-item label="交付实施" prop="deliveryImplementId">
        <el-select
          v-model="formData.deliveryImplementId"
          placeholder="请选择交付实施"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in deliveryImplementIdOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="系统交付过程是否合格" prop="deliveryIsPass">
        <el-select
          v-model="formData.deliveryIsPass"
          placeholder="请选择系统交付过程是否合格"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in deliveryIsPassOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="交付结果" prop="deliveryResult">
        <el-input
          v-model="formData.deliveryResult"
          placeholder="请选择交付结果"
          clearable
          :style="{ width: '100%' }"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="交付资料稽核" prop="isPass">
        <el-select
          v-model="formData.isPass"
          placeholder="请选择交付资料稽核"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in isPassOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item size="mini">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import BasicBusiness from "@/views/components/business/BasicBusiness.vue";
import Step from "@/views/components/business/Step.vue";

import {
  getProjectDetail,
  getDeliveryImplement,
  deliveryCheck,
} from "@/api/project/index";
export default {
  components: { BasicBusiness, Step },
  props: [],
  data() {
    return {
      formData: {
        deliveryImplementId: undefined,
        deliveryIsPass: undefined,
        deliveryResult: undefined,
        isPass: undefined,
      },
      rules: {
        // deliveryImplementId: [
        //   {
        //     required: true,
        //     message: "请选择交付实施",
        //     trigger: "change",
        //   },
        // ],
        deliveryIsPass: [
          {
            required: true,
            message: "请选择系统交付过程是否合格",
            trigger: "change",
          },
        ],
        deliveryResult: [
          {
            required: true,
            message: "请选择交付结果",
            trigger: "blur",
          },
        ],
        isPass: [
          {
            required: true,
            message: "请选择交付资料稽核",
            trigger: "change",
          },
        ],
      },
      // deliveryImplementIdOptions: [

      // ],
      deliveryIsPassOptions: [
        {
          label: "不合格",
          value: 0,
        },
        {
          label: "合格",
          value: 1,
        },
      ],
      isPassOptions: [
        {
          label: "不通过",
          value: 0,
        },
        {
          label: "通过",
          value: 1,
        },
      ],
    };
  },
  computed: {
    boId() {
      return this.$route.query.boId;
    },
    projectId() {
      return this.$route.query.projectId;
    },
  },
  watch: {},
  created() {},
  mounted() {
    this.loadData();
  },
  methods: {
    loadData() {
      this.$refs.basicBusinessRef.loadData(this.boId).then((res) => {});

      getProjectDetail(this.boId).then((res) => {
        this.stage = res.data.stage;
        this.$refs.stepRef.setStage(this.stage);
      });

      getDeliveryImplement(this.boId).then((res) => {
        console.log(res, "===");
        // this.deliveryImplementIdOptions = res.rows
        this.formData.deliveryImplementId = res.rows[0].id;
      });
    },
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单
        deliveryCheck({
          ...this.formData,
          boId: this.boId,
          projectId: this.projectId,
        }).then((res) => {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          this.$router.replace('/check/index');
        });
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
